<?php

namespace App\Http\Controllers\Api\Ucenter;

use App\Commons\Domain\Module\UserCenter\Model\Member;
use App\Commons\Libs\Annotations\UserLog;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\Ucenter\User\ChangeJypwdRequest;
use App\Http\Requests\Api\Ucenter\User\CodeRequest;
use App\Http\Requests\Api\Ucenter\User\LoginRequest;
use App\Http\Requests\Api\Ucenter\User\LogsRequest;
use App\Http\Requests\Api\Ucenter\User\RegisterRequest;
use App\Http\Requests\Api\Ucenter\User\ResetRequest;
use App\Http\Requests\Api\Ucenter\User\SetJypwdRequest;
use App\Http\Requests\Api\Ucenter\User\SwitchNoticeRequest;
use App\Http\Requests\Api\Ucenter\User\UpdateInfoRequest;
use App\Http\Requests\Api\Ucenter\User\UpdatePwdRequest;
use App\Logics\Api\Ucenter\UserLogic;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Request;

/**
 *
 * @authors generator
 * @date    2020-10-19 16:51:40
 */
class UserController extends Controller
{
    protected UserLogic $logic;

    function __construct(UserLogic $logic)
    {
        $this->logic = $logic;
    }

    /**
     * 注册 /api/user/register
     *
     * @param RegisterRequest $request [description]
     * @return JsonResponse
     * @throws GuzzleException
     */
    public function register(RegisterRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象
        $result = $this->logic->register($param);

        return ok($result);
    }

    /**
     * 登录 /api/user/login
     *
     * @param LoginRequest $request [description]
     * @return JsonResponse
     * @throws \Exception
     */
    public function login(LoginRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->login($param, $request->ip());

        return ok($result);
    }

    /**
     * 获取验证码 /api/user/code
     *
     * @param CodeRequest $request [description]
     * @return JsonResponse
     */
    public function code(CodeRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->code($param);

        return ok($result);
    }

    /**
     * 用户信息 /api/ucenter/user/info
     *
     * @param Request $request [description]
     * @return JsonResponse
     */
    public function info(Request $request)
    {

        $result = $this->logic->info();

        return ok($result);
    }

    /**
     * 用户信息 /api/ucenter/user/info
     *
     * @param UpdateInfoRequest $request [description]
     * @return JsonResponse
     */
    public function updateInfo(UpdateInfoRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->updateInfo($param);

        return ok($result);
    }


    /**
     * 退出 /api/ucenter/user/logout
     *
     * @param Request $request [description]
     * @return JsonResponse
     */
    public function logout(Request $request)
    {

        $result = $this->logic->logout();

        return ok($result);
    }

    /**
     * 重置密码 /api/ucenter/user/reset
     *
     * @param ResetRequest $request [description]
     * @return JsonResponse
     */
    public function reset(ResetRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->reset($param);

        return ok($result);
    }

    /**
     * 修改密码
     * @param UpdatePwdRequest $request
     * @return JsonResponse
     */
    public function updatePwd(UpdatePwdRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->updatePwd($param);

        return ok($result);
    }

    /**
     * 获取用户操作记录
     * @UserLog()
     * @param LogsRequest $request
     * @return JsonResponse
     */
    public function logs(LogsRequest $request)
    {
        //日志来源：1.登录，2安全设置，3交易
        $params = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->getLogs($params);

        return ok($result);
    }

    /**
     * 开启和关闭通知状态
     * @param SwitchNoticeRequest $request
     * @return JsonResponse
     */
    public function switchNotice(SwitchNoticeRequest $request)
    {
        //日志来源：1.登录，2安全设置，3交易
        $params = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->switchNotice($params['type'], $params['status']);

        return ok($result);
    }

    /**
     * 获取通知状态
     * @param Request $request
     * @return JsonResponse
     */
    public function memberNotice(Request $request)
    {

        $user = auth()->user();

        $result = Member::whereUid($user->uid)->select('email_setting', 'sms_setting')->first();

        return ok($result);
    }


    /**
     * 国家列表 /api/ucenter/user/country
     *
     * @param Request $request [description]
     * @return JsonResponse
     */
    public function country(Request $request)
    {

        $result = $this->logic->country();

        return ok($result);
    }

    /**
     * 设置资金密码 /api/ucenter/user/set-jypwd
     *
     * @param SetJypwdRequest $request [description]
     * @return JsonResponse
     */
    public function setJypwd(SetJypwdRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->setPwd($param);

        return ok($result);
    }

    /**
     * 修改资金密码 /api/ucenter/user/change-jypwd
     *
     * @param ChangeJypwdRequest $request [description]
     * @return JsonResponse
     */
    public function changeJypwd(ChangeJypwdRequest $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象

        $result = $this->logic->changePwd($param);

        return ok($result);
    }

    public function test(Request $request)
    {
        $param = $request->params();  // params方法传入对应的Param对象


        return ok(11);
    }

    /** #generate function# 删除后将无法自动生成控制器方法 */
}
